/*
 *	Copyright (C) 2008 CRIMERE
 *	Copyright (C) 2008 Jean-Marc Mercier
 *	
 *	This file is part of OTS (optimally transported schemes), an open-source library
 *	dedicated to scientific computing. http://code.google.com/p/optimally-transported-schemes/
 *
 *	CRIMERE makes no representations about the suitability of this
 *	software for any purpose. It is provided "as is" without express or
 *	implied warranty.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#define NUMBER_OF_PARTICLES 10

#if !defined(_Cauchy_D__x_)
#define _Cauchy_D__x_
#include <set>
#include <src/algorithm/random/NormalGenerator.h>
#include <src/math/Operators/all.h>
#include <src/algorithm/Evolution_Algorithm/Crank_Nicolson.h>
#include <src/algorithm/Evolution_Algorithm/ForwardEuler.h>
#include <src/math/BoundaryCondition/BoundaryCondition.h>
#include <src/math/CauchyProblems/CauchyProblem_traits.h>
#include <src/math/functor/2D_representation.h>

template<class data>
struct CrankNicolson_D__x : public Crank_Nicolson<D__x_t<data>>
{
	OS_STATIC_CHECK(data::Dim == 1); // not sure of the multidimensional behavior. To test before.
	virtual OS_double CFL() {
		return .5/ get_state_variable()->size();
	};
	virtual bool criteria() {
		OS_double breakpoint1 = jmmath::norm22(Op_iterate - Op_S_k1);
		OS_double breakpoint2 = jmmath::norm22(Op_iterate);
		return breakpoint1/(1.+breakpoint2) < 1e-4;
	};
};
/** @ingroup Transport_equations
   @brief backward difference scheme solving the transport equation @link Simple_transport_equation@endlink

   This Cauchy problem illustrates the behavior of the finite difference scheme
	\f[ 
		\delta_t u^n = \delta_{x} u^{n+1/2} = 0 
	\f];
	The algorithm used is Crank Nicolson.
	The boundary conditions are given by <data> : either Dirichlet or Periodic ones.
	The initial data corresponds to a normal distribution centered in 0.5.
*/
template <class data, class Interface = Graphical_Interface>
		class Cauchy_D__x : public CauchyProblem_traits< CrankNicolson_D__x < data >, Interface>
		{
		public :
			Cauchy_D__x(){
				initial_conditions(NUMBER_OF_PARTICLES);
			};
			virtual smart_ptr<interface_type> Create_Instance() {
				return smart_ptr<interface_type>(new Cauchy_D__x);
			};

			virtual void set_dim(OS_size dim) {
				OS_DYNAMIC_CHECK(dim == 1,"try to initialise a one dimensional Cauchy problem Cauchy_D_x with an higher dimension");
			};
			OS_size get_dim() {return 1;};
			void initial_conditions(OS_size nb_part) {
				set_initial_conditions(Gaussian_Functor<data>()(nb_part));
			};
		};

#undef NUMBER_OF_PARTICLES

#endif